<?php
require("../../common/init.php");
require("author.php");
require("upfile.php");

$feedback=new DB(Tfeedback,$conn);
$gee=$feedback; // gee, 意为赶车时候喊的"驾", 此处用来表示次页面的主角对象
//$cate=$language; // cate = category, 分类
$gee->rows=15;

$title=ROOT_CUSTOMER_FEEDBACK;
$url='feedback';
$do=isset($_GET["do"])?clean($_GET["do"]):'view'; // 操作: 查看/编辑/删除 
$action=isset($_POST["action"])?clean($_POST["action"]):''; // 数据库操作: CURD 
$id=0; if (isset($_GET["id"])) $id = clean($_GET["id"]);
$cateid=0; if (isset($_GET["cateid"])) $cateid = clean($_GET["cateid"]);

// sql action / sql 动作
switch ($action){
	case "update": sql_update(); break;
	case "add": sql_insert(); break;
	case "deletes": sql_delete(); break;
}

if($id==0){
	$page=1; if(isset($_GET["page"]))if(is_numeric($_GET["page"]))$page=$_GET["page"];
	$order='id';
	$where=array();
	$pages=$gee->count_pages($where);
	$info=$gee->get_page($page,$where,$order);
}
else $info=$gee->get_row($id);

// functions
function update($uid) // to be continued, 未完成
{
	global $gee;
	if($uid=="") 
	{
		echo "Invali argument!!!";
		exit;
	}
	$info=$gee->echo_only($uid);
	echo '<form method="post" action="message.php">';
  	show_box($info, true);
	echo '<input type="hidden" name="sql" value="update"></form>';
}

function delete($id)
{
	global $gee,$url;
	if($gee->delete($id))
	wheel($url.'.php');
}
function show_info($info)
{
	global $id;
	if($id==0) show_boxes($info);
	else show_box($info, false);
}
function sql_update() // to be continued, 未完成
{
	global $gee;
	if($gee->update( iso(@$_POST["id"]), iso(@$_POST["fullname"]), iso(@$_POST["email"]), iso(@$_POST["words"]) ) )
	echo '<script type="text/javascript">location="message.php";</script>';
}
function sql_delete()
{
	global $gee,$page,$url,$cateid;
	$page=iso(@$_POST["page"]); $cateid=iso(@$_POST["cateid"]);
	$all=$_POST["all"];
	$arrdelete=array();
	if(count($all)>0)foreach($all as $a){ $arrdelete[]=$a; }
	if($gee->delete_rows($arrdelete))
	wheel($url.'-'.$cateid.'-p'.$page.'.html');
}

// view 加载视图
require ROOTVIEW.$url.'.php';

// end feedback.php